package com.tian.framework.config;

import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@Configuration
@EnableOpenApi
public class SwaggerConfig {

    public static final String VERSION = "1.0.0";

    @Bean
    public Docket createAdminApi() {
        return new Docket(DocumentationType.OAS_30)
                .groupName("adminApi")//swagger组的名字
                .apiInfo(adminApiInfo())
                .select()
                //使用注解扫描，扫描所有带注解的方法
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                //包扫描路径
                //.apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_BASE_PACKAGE))
                .paths(PathSelectors.ant("/security/api/adminApi/**")) // 要加context path前缀
                .build();
    }
    @Bean
    public Docket createUserApi() {
        return new Docket(DocumentationType.OAS_30)
                .groupName("userApi")//swagger组的名字
                .apiInfo(userApiInfo())
                .select()
                //使用注解扫描，扫描所有带注解的方法
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                //包扫描路径
                //.apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_BASE_PACKAGE))
                .paths(PathSelectors.ant("/security/api/userApi/**")) // 要加context path前缀
                .build();
    }

    private ApiInfo adminApiInfo() {
        return new ApiInfoBuilder()
                .title("个人项目接口文档") //设置文档的标题
                .description("接口文档") // 设置文档的描述
                .version(VERSION) // 设置文档的版本信息-> 1.0.0 Version information
                .contact(new Contact("天之涯", "http://baidu.com", "travel.my.world@qq.com"))
                .build();
    }
    private ApiInfo userApiInfo() {
        return new ApiInfoBuilder()
                .title("个人项目接口文档") //设置文档的标题
                .description("接口文档") // 设置文档的描述
                .version(VERSION) // 设置文档的版本信息-> 1.0.0 Version information
                .contact(new Contact("天之涯", "http://baidu.com", "travel.my.world@qq.com"))
                .build();
    }
}
